const mqtt = require('mqtt')

function start(cb) {
  var client = mqtt.connect()
  client.on('connect', function() {
    console.log('333')
    cb.connect && cb.connect(client)
  })

  client.on('message', function(topic, payload) {
    console.log('444')
    cb.message && cb.message(client, topic, payload)
  })

  client.on('error', function(err) {
    console.warn(err)
    client.end()
  })
}
exports.start = start